package com.ax.base.drugadministration.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ax.base.common.domain.Tree;
import com.ax.base.drugadministration.domain.BaseDrugDep;
import com.ax.base.system.domain.MenuDO;

@Mapper
public interface BaseDrugDepMapper {
    int deleteByPrimaryKey(Long drugDepId);

    int insert(BaseDrugDep record);
    
    /**
	 * 药监保存(模块:药监部门)
	 * 
	 * @param BaseDrugDep baseDrugDep
	 *           
	 * @return SUCC
	 */
    @Insert("<script>" +
       "insert into base_drug_dep (Drug_Dep_ID, Drug_Dep_Code, Drug_Dep_Name,"+ 
       "First_Letter, Full_Name, Parent_Drug_Dep_ID,"+ 
       "Drug_Dep_Type, Registrar_ID, Registrar_Name,"+ 
       "create_date, update_date, Flag,Area_Code,Area_Name"+
       ")"+
       "values (#{drugDepId}, #{drugDepCode}, #{drugDepName},"+ 
       "#{firstLetter}, #{fullName}, #{parentDrugDepId},"+
       "#{drugDepType}, #{registrarId}, #{registrarName},"+ 
       "NOW(),NOW(), #{flag},#{areaCode},#{areaName}"+
       ")"+
       "</script>")
    int insertSelective(BaseDrugDep record);

    BaseDrugDep selectByPrimaryKey(Long drugDepId);
    
    /**
	 * 药监修改(模块:药监部门)
	 * 
	 * @param BaseDrugDep baseDrugDep
	 *           
	 * @return SUCC
	 */
    @Update("<script>" +
      "update base_drug_dep"+
      "<set >"+
      "<if test=\"drugDepCode != null and drugDepCode != ''\">"+ "Drug_Dep_Code = #{drugDepCode}, " + "</if>" + 
      "<if test=\"drugDepName != null and drugDepName != ''\">"+ "Drug_Dep_Name = #{drugDepName}, " + "</if>" + 
      "<if test=\"areaCode != null and areaCode != ''\">"+ "Area_Code = #{areaCode}, " + "</if>" + 
      "<if test=\"areaName != null and areaName != ''\">"+ "Area_Name = #{areaName}, " + "</if>" + 
      "<if test=\"firstLetter != null and firstLetter != ''\">"+ "First_Letter = #{firstLetter}, " + "</if>" + 
      "<if test=\"fullName != null and fullName != ''\">"+ "Full_Name = #{fullName}, " + "</if>" + 
      "<if test=\"parentDrugDepId != null\">"+ "Parent_Drug_Dep_ID = #{parentDrugDepId}, " + "</if>" + 
      "<if test=\"drugDepType != null and drugDepType != ''\">"+ "Drug_Dep_Type = #{drugDepType}, " + "</if>" + 
      "<if test=\"registrarId != null\">"+ "Registrar_ID = #{registrarId}, " + "</if>" + 
      "<if test=\"registrarName != null and registrarName != ''\">"+ "Registrar_Name = #{registrarName}, " + "</if>" + 
      "create_date = NOW(),"+
      "update_date = NOW(),"+
      "<if test=\"flag != null\">"+ "Flag = #{flag}," + "</if>" + 
      "</set>"+
      "where Drug_Dep_ID = #{drugDepId}"+
      "</script>")
    int updateByPrimaryKeySelective(BaseDrugDep record);

    int updateByPrimaryKey(BaseDrugDep record);
    
    /**
	 * 药监查询(模块:药监部门)
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return List<BaseDrugDep>
	 */
    @Select("<script>" +
	 "select Drug_Dep_ID menuId,Drug_Dep_Code drugDepCode,Drug_Dep_Name name,First_Letter firstLetter,"+
	 "Full_Name fullName,Parent_Drug_Dep_ID parentId,Drug_Dep_Type type,Registrar_Name registrarName,"+
	 "Flag flag,Area_Code areaCode,Area_Name areaName,create_date createDate from base_drug_dep" + 
	 "<where>" + 
  	 "<if test=\"drugDepId != null\">"+ "and Drug_Dep_ID = #{drugDepId} " + "</if>" + 
  	 "</where>"+ 
	 "</script>")
    List<BaseDrugDep> queryDrugAdministrationDepMapper(Map<String, Object> params);
    
    /**
	 * 药监查询(模块:药监部门)*跳转增加页面
	 * 
	 * @param Long pId
	 *           
	 * @return BaseDrugDep baseDrugDep
	 */
    @Select("<script>" +
	 "select Drug_Dep_ID menuId,Drug_Dep_Code drugDepCode,Drug_Dep_Name name,First_Letter firstLetter,"+
	 "Full_Name fullName,Parent_Drug_Dep_ID parentId,Drug_Dep_Type type,Registrar_Name registrarName,"+
	 "Flag flag,Area_Code,Area_Name from base_drug_dep " + 
	 "where Drug_Dep_ID = #{drugDepId}" + 
	 "</script>")
     BaseDrugDep getDrugAdministrationDepMapper(Long drugDepId);
    
    /**
	 * 药监状态修改(模块:药监部门)
	 * 
	 * @param String[] parameter,Integer flag
	 *           
	 * @return SUCC
	 */
    @Update("<script>"+
    "update base_drug_dep set Flag = #{flag}"+
    "where Drug_Dep_ID in"+
    "<foreach collection='list' index='index' item='item' open='(' separator=',' close=')'>"+
    "#{item}"+
    "</foreach>"+
    "</script>")
     void updateStateMapper(Map<String,Object> map);
    
    /**
	 * 树形列表(药监部门)
	 * 
	 * @param 无
	 *           
	 * @return Tree<MenuDO>
	 */
    @Select("SELECT Drug_Dep_ID id,Drug_Dep_Name text, Parent_Drug_Dep_ID parentId FROM base_drug_dep")
    List<Tree<MenuDO>> listDep();
    
    /**
	 * 名字是否重复(新增)
	 * 
	 * @param String parameter
	 *         
	 * @return boolean
	 */
    @Select("<script>" +
	 "select Drug_Dep_ID menuId,Drug_Dep_Code drugDepCode,Drug_Dep_Name name,First_Letter firstLetter,"+
	 "Full_Name fullName,Parent_Drug_Dep_ID parentId,Drug_Dep_Type type,Registrar_Name registrarName,"+
	 "Flag flag,Area_Code areaCode,Area_Name areaName,create_date createDate from base_drug_dep where Drug_Dep_Name = #{drugDepName} and Parent_Drug_Dep_ID = #{parentDrugDepId}" + 
	 "</script>")
    List<BaseDrugDep> validateMapper(Map<String,Object> map);
    
    /**
	 * 名字是否重复(修改)
	 * 
	 * @param String parameter
	 *         
	 * @return boolean
	 */
    @Select("<script>" +
	 "select Drug_Dep_ID menuId,Drug_Dep_Code drugDepCode,Drug_Dep_Name name,First_Letter firstLetter,"+
	 "Full_Name fullName,Parent_Drug_Dep_ID parentId,Drug_Dep_Type type,Registrar_Name registrarName,"+
	 "Flag flag,Area_Code areaCode,Area_Name areaName,create_date createDate from base_drug_dep where Drug_Dep_Name = #{drugDepName} and Parent_Drug_Dep_ID = #{parentDrugDepId} and Drug_Dep_ID != #{drugDepId}" + 
	 "</script>")
    List<BaseDrugDep> validateUpdateMapper(Map<String,Object> map);
    
    /**
	 * Tree
	 * 
	 * @param Long parentDrugDepId
	 *           
	 * @return List<Tree<MenuDO>>
	 */
    @Select("SELECT Drug_Dep_ID id,Drug_Dep_Name text, Parent_Drug_Dep_ID parentId FROM base_drug_dep")
    List<Tree<MenuDO>> listDrugDepId();
    
}